/**
 * @properties={typeid:35,uuid:"CA272883-3C79-4980-8A3A-790694E2C305",variableType:-4}
 */
var $NOMBRE_SERVIDOR = globals.$NOMBRE_SERVIDOR;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"52454382-0ECB-4CAA-9DE4-E22ABDB88AE7"}
 */
var $NOMBRE_TABLA = "adm_t900_menus";

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"D871D5BC-C895-4A25-8A0D-87AE97595ACD"}
 */
var $DATA_SOURCE = "db:/" + $NOMBRE_SERVIDOR + "/" + $NOMBRE_TABLA;

/**
 * Inicializa los menús
 * @author Roberto J. Blasco
 * @version 1.0
 * @properties={typeid:24,uuid:"021C328E-86DF-4D0F-A8C0-79BE9D264910"}
 */
function inicializar_menus(){
	
	/** @type {JSFoundSet<db:/pigeon_board/adm_t900_menus>} */
	var fs_adm_t900_menus = databaseManager.getFoundSet($DATA_SOURCE);
	fs_adm_t900_menus.loadAllRecords();
	
	if (fs_adm_t900_menus.getSize() == 0){
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 100;
		fs_adm_t900_menus.s_descripcion = "Inicio";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_home_white_18dp.png";
		databaseManager.saveData(fs_adm_t900_menus);
		var id_inicio = fs_adm_t900_menus.getRecord(1).adm_t900_menus_id;
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 101;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_inicio;
		fs_adm_t900_menus.s_descripcion = "Sobre";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_help_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "sobre";
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 102;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_inicio;
		fs_adm_t900_menus.s_descripcion = "Salir";
		fs_adm_t900_menus.s_descripcion = "salir";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_settings_white_18dp.png";
		databaseManager.saveData(fs_adm_t900_menus);
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 200;
		fs_adm_t900_menus.s_descripcion = "Administración";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_settings_phone_white_18dp.png";
		databaseManager.saveData(fs_adm_t900_menus);
		var id_adm = fs_adm_t900_menus.getRecord(1).adm_t900_menus_id;
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 201;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_adm;
		fs_adm_t900_menus.s_descripcion = "Aplicaciones";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_dns_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "f_adm_aplicaciones";
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 202;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_adm;
		fs_adm_t900_menus.s_descripcion = "Empresas";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_dns_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "f_adm_empresas";
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 203;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_adm;
		fs_adm_t900_menus.s_descripcion = "Perfiles";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_dns_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "f_adm_perfiles";
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 204;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_adm;
		fs_adm_t900_menus.s_descripcion = "Usuarios";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_dns_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "f_adm_usuarios";
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 205;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_adm;
		fs_adm_t900_menus.s_descripcion = "Roles";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_dns_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "f_adm_roles";
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 206;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_adm;
		fs_adm_t900_menus.s_descripcion = "Tablas";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_dns_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "f_adm_tablas";
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 207;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_adm;
		fs_adm_t900_menus.s_descripcion = "Menús";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_dns_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "f_adm_menus";
		databaseManager.saveData(fs_adm_t900_menus);
	}
}

/**
 * Despliega el menú<br>
 * Si no se le pasa parámetro muestra sólo los menus iniciales
 * @author Roberto J. Blasco
 * @version 1.0
 * @param {JSRecord<db:/pigeon_board/adm_t900_menus>} [record_adm_t900_menus]
 * @return {JSFoundSet<db:/pigeon_board/adm_t900_menus>}
 *
 * @properties={typeid:24,uuid:"AD8D3B67-DED0-43F0-8AEF-379769AA1D6B"}
 * @AllowToRunInFind
 */
function mostrar_menu(record_adm_t900_menus){
	
	// Mostramos sólo los menús asociados a su perfil
	/** @type {JSFoundSet<db:/pigeon_board/adm_t900_menus>} */
	var fs_adm_t900_menus = databaseManager.getFoundSet(scopes.adm_t900_menus.$DATA_SOURCE)
	fs_adm_t900_menus.loadAllRecords();
	
	if (record_adm_t900_menus == null){
		if (fs_adm_t900_menus.find()){
			fs_adm_t900_menus.adm_t900_menus_padre_id = '^';
			fs_adm_t900_menus.search();
		}
		application.output(fs_adm_t900_menus.getSize());
		return fs_adm_t900_menus;
	}else{
		if (fs_adm_t900_menus.find()){
			fs_adm_t900_menus.adm_t900_menus_padre_id = '^';
			fs_adm_t900_menus.newRecord();
			fs_adm_t900_menus.adm_t900_menus_padre_id = record_adm_t900_menus.adm_t900_menus_id;
			fs_adm_t900_menus.search();
			fs_adm_t900_menus.sort("n_orden  asc")
		}
		return fs_adm_t900_menus;
	}
}

/**
 * @properties={typeid:24,uuid:"04D03F6A-24B4-4E22-8E8D-E8B2A38222B6"}
 */
function salir(){
	
	application.exit();
}

/**
 * @properties={typeid:24,uuid:"8E4E570F-F874-49E6-8926-2DA792DD97AB"}
 */
function sobre(){
	
	application.output(application.getSolutionName());
}

/**
 * @properties={typeid:24,uuid:"C110A48E-AE74-4EAF-93F9-E137B67F36AD"}
 */
function menu_navigator(){
	
	forms[globals.$frm_siv_main].elements.tab_principal.removeAllTabs();
	forms[globals.$frm_siv_main].elements.tab_principal.addTab(forms.lst_adm_t900_menus);
}
